﻿Imports System.IO

Public Class frmBackupDB
    Dim MySQLDumpPart As String = Application.StartupPath & "\mysqldump.exe"

    Private Sub BtnDumpSQL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDumpSQL.Click
        If MsgBox("ยืนยันการสำรองข้อมูล", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.No Then Exit Sub
        'C:\Program Files\HOSxP\MySQL\bin\mysqldump.exe
        Try
            With Me.SaveFileDialog1
                .Title = "เลือก folder ที่ต้องการบันทึก"
                .FileName = "whis.sql"
                .Filter = "MySQL Backup File SQL|*.sql"
                .ShowDialog()
                Process.Start(MySQLDumpPart, " --user=" & ClsSQLhelper.MySQLUser & " --password=" & ClsSQLhelper.MySQLPassword & " --host=" & ClsSQLhelper.MySQLServer & " --databases " & ClsSQLhelper.MySQLDatabase & " < -r """ & .FileName & """")
                MsgBox("สำรองข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            End With
        Catch ex As Exception

        End Try

    End Sub

    Private Sub frmBackupDB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IO.File.Exists(Application.StartupPath & "\Addon\mysqldump.exe") = False Then
            With Me.OpenFileDialog1
                .Title = "เลือก MySQLDump.EXE path"
                .FileName = "MySQLDump.EXE"
                .Filter = "MySQLDump.EXE EXE|*.exe"
                .ShowDialog()
                MySQLDumpPart = .FileName
            End With
        End If
    End Sub
End Class